﻿using System;
using System.Linq;
using nsadv.Statistic.Domain;
using nsadv.Statistic.Repository;

namespace nsadv.Statistic.Services.Security
{
	public class Membership
	{
		private readonly User _anonymouse = new User() { Id = null, Name = "Anonymouse", Role = UserRole.None };

		protected readonly IRepository<User> Repository;

		public Membership(IRepository<User> repository)
		{
			Repository = repository;
		}

		public User Anonymouse
		{
			get { return _anonymouse; }
		}

		public User GetUserById(string userId)
		{
			return Repository.ById(userId);
		}

		public bool ValidateUser(string name, string password, out User user)
		{
			user = Repository.All.FirstOrDefault(x => x.Name == name && x.Password == password);
			return user != null;
		}
	}
}
